﻿// labelUi.h : labelUi DLL 的主头文件
//

#pragma once

#include <afxwin.h>
#include "labelDriverDef.hpp"
#include "labelDeviceBase.hpp"
#include "labelUiDef.hpp"
#include <ossLock.h>
#include <Osslist.h>

class LabelUiBase : public CWnd
{
public:
    LabelUiBase(LabelUiBase* pParentLabelUi, OssJson& createInfo);
    LabelUiBase(LabelUiBase* pParentLabelUi, OssJson& createInfo
            , HandleUiRequestFun handleRequestFun, LPVOID handleContext);
    virtual ~LabelUiBase();

    /**
     *      日志输出
     */
    void WriteLog(LogPriority priority,const char* format,...);

    void SetDeviceId(const char* deviceId);
	const char* GetDeviceId();

	/**
     *		设置窗口内容
	 */
	virtual void SetContent(OssJson& jsonContent);

    /**
     *      创建
     */
    virtual void CreateUi();

    /**
     *      销毁
     */
    virtual void DestroyUi();

    /**
     *      更新UI
     */
    virtual void UpdateUi(OssJson& updateUiInfo);

    /**
     *      处理请求
     *@strParam     下发的请求,请将TransactionId和DeviceID使用%s代替，
	 *				例如："{\"msgId\":\"getRelayAgentInfo\",\"tsId\":%d,\"deviceId\":\"%s\",\"msg\":{\"pageIndex\":0,\"pageSize\":20}}";
     *@iParamLen    请求内容长度
     *@dwMsgId      请求
     */
    BOOL SendRequest(OssJson& requestParam,DWORD dwMsgId);

    void LockUi();
    void UnlockUi();
    DECLARE_MESSAGE_MAP()

protected:

    /**
     *      size change
     */
    virtual void SizeChange(UINT nType, int cx, int cy);
 
	afx_msg void OnDestroy();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg LRESULT OnCreateUi(WPARAM wParam,LPARAM lParam);
protected:
	HandleUiRequestFun		m_handleRequestFun;
	LPVOID					m_handleContext;
    
    OssCritical             m_uiCritical;
    OssJson                 m_createInfo;
    char					m_acDeviceId[DEVICE_ID_MAX];	//绑定的设备ID 
};


/**
 *      定义驱动的入口，必须是LabelUiBase的派生类
 */
#define LABEL_UI_ENTRY(entry) OSS_EXTERN_BEG \
                                    DLL_API LabelUiBase* CreateDriverUi(LabelUiBase *pParentLabelUi,OssJson& createInfo) \
                                                {\
                                                    entry *pE = (new entry(pParentLabelUi,createInfo));\
                                                    if(pE->Create(NULL,NULL,WS_CHILD | WS_VISIBLE,CRect(0,0,0,0),pParentLabelUi,0Xffff,NULL)) \
                                                    {\
                                                        return pE;\
                                                    }\
                                                    else\
                                                    {\
                                                        delete pE;\
                                                        return NULL;\
                                                    }\
                                                    return pE;\
                                                }\
                                extern OssVersion g_version;\
                                DLL_API OssVersion* GetDriverUiVersion()\
                                                {\
                                                    return &g_version;\
                                                }\
                        OSS_EXTERN_END




